package com.hardware.protocol.mqtt;

import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.nutz.ioc.loader.annotation.IocBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @Describe 接收消息回调
 * @Author hy
 * @Date 18:07 2023/8/3
 * @version 1.0
 **/
@Component
public class MqttRecieveCallback implements MqttCallback {
    private static final Logger log = LoggerFactory.getLogger(MqttRecieveCallback.class);
    @Override
    public void connectionLost(Throwable throwable) {
        log.error("connectionLost: " + throwable.getMessage());
    }

    @Override
    public void messageArrived(String topic, MqttMessage message) throws Exception {
        log.info("Client 接收消息主题 : " + topic);
        log.info("Client 接收消息Qos : " + message.getQos());
        log.info("Client 接收消息内容 : " + new String(message.getPayload()));
    }

    @Override
    public void deliveryComplete(IMqttDeliveryToken token) {

    }

}
